using System;
using System.ComponentModel;
using Iesi.Collections.Generic;
using Castle.Components.Validator;
using NHibernate.Search.Attributes;
using WineCellar.Business.Entities;
using WineCellar.Core.Converters;

namespace WineCellar.Business.Entities
{   
    [Indexed(Index = "Wine")]
    [TypeConverter(typeof(EntityConverter<Wine>))]
    public partial class Wine
    {
        private ISet<Raisin> raisins = new HashedSet<Raisin>();
				
        [ValidateNonEmpty("Name is a required field")]        
        [Field(Index.Tokenized, Store = Store.No)]
        public virtual string Name { get; set; }

        [Field(Index.Tokenized, Store = Store.No)]
        public virtual string Producer { get; set; }

        [Field(Index.Tokenized, Store = Store.No)]
        public virtual string Appelation { get; set; }

        [Field(Index.Tokenized, Store = Store.No)]
        public virtual string ColorType { get; set; }

        [Field(Index.Tokenized, Store = Store.No)]
        public virtual DateTime? DateAdded { get; set; }
        
        [DocumentId]
        public virtual int? Id { get; set; }

        [ValidateNonEmpty("Region is required")]    
        [IndexedEmbedded]
        public virtual Region Region { get; set; }
        
        [IndexedEmbedded]
        public virtual User AddedBy { get; set; }
               
        public virtual ISet<Raisin> Raisins
        {
            get{return raisins;}
            set{raisins = value;}
        }

        public virtual Guid SecurityKey { get; set; }

        public override string ToString()
        {
            return this.Name;
        }
    }
}